﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria.Chat;

namespace Terraria.ModLoader.Default
{
	// Token: 0x020002FB RID: 763
	internal class HelpCommand : ModCommand
	{
		// Token: 0x170001E1 RID: 481
		// (get) Token: 0x06001D2A RID: 7466 RVA: 0x00014A78 File Offset: 0x00012C78
		public override string Command
		{
			get
			{
				return "help";
			}
		}

		// Token: 0x170001E2 RID: 482
		// (get) Token: 0x06001D2B RID: 7467 RVA: 0x00014A7F File Offset: 0x00012C7F
		public override string Usage
		{
			get
			{
				return "/help [name]";
			}
		}

		// Token: 0x170001E3 RID: 483
		// (get) Token: 0x06001D2C RID: 7468 RVA: 0x00014A86 File Offset: 0x00012C86
		public override CommandType Type
		{
			get
			{
				return CommandType.Chat | CommandType.Server;
			}
		}

		// Token: 0x06001D2D RID: 7469 RVA: 0x0043850C File Offset: 0x0043670C
		public override void Action(CommandCaller caller, string input, string[] args)
		{
			if (args.Length == 0)
			{
				List<Tuple<string, string>> help = CommandManager.GetHelp(caller.CommandType);
				caller.Reply(caller.CommandType + " Commands:", Color.Yellow);
				foreach (Tuple<string, string> tuple in help)
				{
					caller.Reply(tuple.Item1 + "   " + tuple.Item2, default(Color));
				}
				if (Main.netMode == 1)
				{
					NetMessage.SendChatMessageFromClient(new ChatMessage(input));
				}
				return;
			}
			ModCommand modCommand;
			if (!CommandManager.GetCommand(caller, args[0], out modCommand))
			{
				throw new UsageException("Unknown command: " + args[0], Color.Red);
			}
			if (modCommand != null)
			{
				caller.Reply(modCommand.Usage, default(Color));
				if (!string.IsNullOrEmpty(modCommand.Description))
				{
					caller.Reply(modCommand.Description, default(Color));
				}
			}
		}
	}
}
